package com.bestv.search.common.dao.hibernate;

import com.bestv.search.common.dao.UserAccessDetailDao;
import com.bestv.search.common.model.UserAccessDetail;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import java.sql.SQLException;
import java.util.Date;

public class UserAccessDetailDaoHibernate extends GenericDaoHibernate<UserAccessDetail, Long> implements
        UserAccessDetailDao {

    public void removeByDate(final Date date) {
        getHibernateTemplate().execute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                String hql = "delete UserAccessDetail where date =?";
                Query query = session.createQuery(hql);
                query.setDate(0, date);
                return query.executeUpdate();
            }
        });
    }
}